//
//  CscAppClientApi.m
//  CscAppClient_20151116
//
//  Created by mouxiaochun on 15/12/16.
//  Copyright © 2015年 mmc. All rights reserved.
//

#import "HivesHealthyApi.h"
#import "Methods.h"

@implementation HivesHealthyApi


#pragma mark --- User 模块

/**
 ** 用户注册
 ** registerNo: 手机号码
 ** validCode : 验证码
 ** password  : 密码
 **/
+ (void)driverRegiser:(NSString *)phone code:(NSString *)code password:(NSString *)password type:(NSString *)type completion:(AICompletionBlock)block{

    NSDictionary *param = @{@"phone":phone,@"code":code,@"password":password,@"type":type};
    
    [AIRequest startWithRequestToURL:nil method:_getValidCode jsonParam:param encrypt:YES block:block];


}
/**
 ** 获取验证码  State 类型（0：用户，1：司机）
 **/
+ (void)getValidCodeWithPhone:(NSString *)phone type:(NSString *)type state:(NSString *)state completion:(AICompletionBlock)block {
    NSString *typeStr = [NSString stringWithFormat:@"%zi",type];
    
   NSString *unEncode = [NSString stringWithFormat:@"phone=%@type=&%@&state=%@",phone,type,state];
    
    [DeviceUtility encryptUseDES:unEncode key:@"key"];
    NSDictionary *param = @{@"phone":phone,@"type":typeStr,@"state":state};

    NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:nil];
    NSString *yzm = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *dic = @{@"yzm":yzm};
    
    [AIRequest startWithRequestToURL:nil
                              method:_getValidCode
                           jsonParam:dic
                             encrypt:NO
                               block:block];
}





+ (void)userRegister:(NSString *)phoneNo validCode:(NSString *)validCode password:(NSString *)password completion:(AICompletionBlock)block
{

    NSDictionary *param = @{@"phoneNo":phoneNo,@"validCode":validCode,@"password":password};
   
    [AIRequest startWithRequestToURL:nil
                              method:_registerOfAction
                           jsonParam:param
                             encrypt:NO
                               block:block];
    
}

/**
 ** 用户注册
 ** phoneNo:    手机号码
 ** validCode : 验证码
 **/
+ (void)userLogin:(NSString *)phoneNo validCode:(NSString *)validCode completion:(AICompletionBlock)block {
    
    NSDictionary *param = @{@"phoneNo":phoneNo,@"password":validCode};
    [AIRequest startWithRequestToURL:nil
                              method:_loginOfAction
                           jsonParam:param
                             encrypt:NO
                               block:block];
    
    
}



/**
 ** 用户修改密码
 **/

+ (void)modifyPassword:(NSString *)phoneNo
           password:(NSString *)password
              newPassword:(NSString *)newPassword
            completion:(AICompletionBlock)block {
    NSDictionary *param = @{@"phoneNo":phoneNo,@"password":password,@"newPassword":newPassword};
    [AIRequest startWithRequestToURL:nil
                              method:_uploadNewLoginPwd
                           jsonParam:param
                             encrypt:NO
                               block:block];
}


/**
 ** 用户忘记密码
 **/

+ (void)forgetPhoneNo:(NSString *)phoneNo
            validCode:(NSString *)validCode
             password:(NSString *)password
           completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"phoneNo":phoneNo,@"validCode":validCode,@"newPassword":password};
    [AIRequest startWithRequestToURL:nil
                              method:_userForgetPassword
                           jsonParam:param
                             encrypt:NO
                               block:block];
}


/**
 ** 查询用户基本信息
 ** userId: 用户ID
 **/
+ (void)queryUserInfo:(NSString *)userId completion:(AICompletionBlock)block{
    NSDictionary *param = @{@"userId":userId};
    [AIRequest startWithRequestToURL:nil
                              method:_queryUserInfo
                           jsonParam:param
                             encrypt:NO
                               block:block];
}

/**
 ** 查询用户基本信息
 ** phoneNo: phoneNo手机号码
 ** file: 文件路径
 **/
+ (void)uploadHeadPic:(NSString *)phoneNo uploadType:(NSString *)uploadType file:(NSString *)file completion:(AICompletionBlock)block {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    if (phoneNo.length != 0) {
        [param setObject:phoneNo forKey:@"phoneNo"];
    }
    [param setObject:file forKey:@"file"];
    [param setObject:uploadType forKey:@"uploadType"];
    [AIRequest startWithRequestToURL:nil
                              method:_uploadHeadPic
                           jsonParam:param
                             encrypt:NO
                               block:block];
    
}


+ (void)careByIDCard:(NSString *)userId uploadType:(NSString *)uploadType file:(NSString *)file completion:(AICompletionBlock)block {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    if (userId.length != 0) {
        [param setObject:userId forKey:@"userId"];
    }
    [param setObject:file forKey:@"file"];
    [param setObject:uploadType forKey:@"uploadType"];
    [AIRequest startWithRequestToURL:nil
                              method:_uploadHeadPic
                           jsonParam:param
                             encrypt:NO
                               block:block];
    
}


/**
 ** 用户绑定手机
 ** registerNo: 手机号码
 ** validCode : 验证码
 **/
+ (void)userBindPhoneNubmer:(NSString *)phoneNo validCode:(NSString *)validCode completion:(AICompletionBlock)block {
    
    NSDictionary *param = @{@"userId":@"1",@"phoneNo":phoneNo,@"validCode":validCode};
    [AIRequest startWithRequestToURL:nil
                              method:_bindPhoneOfAction
                           jsonParam:param
                             encrypt:NO
                               block:block];
}


/**
 ** 用户注册后添加资料
 ** phone        : 司机手机号
 ** idcardnumber    : 用户身份证号码
 ** birthday        : 用户出生日期
 ** birthday        : 性别
 ** usernation      : 民族
 ** usernation      : 家庭住址
 **/

//+ (void)userUserId:(NSString *)userId infomation:(NSString *)username idcardnumber:(NSString *)idcardnumber birthday:(NSString *)birthday gender:(NSString *)gender usernation:(NSString *)usernation address:(NSString *)address completion:(AICompletionBlock)block
//{
//    NSDictionary *param = @{@"userId":userId,@"username":username,@"idcardnumber":idcardnumber,@"birthday":birthday,@"gender":gender,@"usernation":usernation,@"address":address};
//    NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:nil];
//    NSString *userInfo = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSDictionary *dic = @{@"userInfo":userInfo};
//    [AIRequest startWithRequestToURL:nil
//                              method:_userInfomation
//                           jsonParam:dic
//                             encrypt:NO
//                               block:block];
//    
//}
/**
** 用户注册后添加资料
** username        : 用户名称
** idcardnumber    : 用户身份证号码
** birthday        : 用户出生日期
** birthday        : 性别
** usernation      : 民族
** usernation      : 家庭住址
**/
//+ (void)userUserId:(NSString *)userId infomation:(NSString *)username idcardnumber:(NSString *)idcardnumber birthday:(NSString *)birthday gender:(NSString *)gender usernation:(NSString *)usernation address:(NSString *)address completion:(AICompletionBlock)block
//{
//    NSDictionary *param = @{@"userId":userId,@"username":username,@"idcardnumber":idcardnumber,@"birthday":birthday,@"gender":gender,@"usernation":usernation,@"address":address};
//    NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:nil];
//    NSString *userInfo = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSDictionary *dic = @{@"userInfo":userInfo};
//    [AIRequest startWithRequestToURL:nil
//                              method:_userInfomation
//                           jsonParam:dic
//                             encrypt:NO
//                               block:block];
//
//}


#pragma mark --- 健康模块
/**
 ** 健康管理，查询各项指标
 ** userId: 用户ID
 **/
+ (void)queryMyIndicators:(NSString *)userId completion:(AICompletionBlock)block {

    NSDictionary *param = @{@"userId":userId};
    [AIRequest startWithRequestToURL:nil
                              method:_queryMyIndicators
                           jsonParam:param
                             encrypt:NO
                               block:block];
}
+ (void)queryMyIndicatorsByCode:(NSString *)userId
                  indicatorCode:(NSString *)indicatorCode
                     queryValue:(NSString *)queryValue
                     completion:(AICompletionBlock)block{
    //queryValue = [queryValue stringByReplacingOccurrencesOfString:@"-" withString:@""];
    NSDictionary *param = @{@"userId":userId,@"indicatorCode":indicatorCode,@"queryValue":queryValue};
    [AIRequest startWithRequestToURL:nil
                              method:_queryMyIndicatorsByCode
                           jsonParam:param
                             encrypt:NO
                               block:block];
    
}

+ (void)queryCaculateIndicators:(NSString *)userId completion:(AICompletionBlock)block {
    NSDictionary *param = @{@"userId":userId};
   AIRequest *request = [AIRequest startWithRequestToURL:nil
                              method:_queryCaculateIndicators
                           jsonParam:param
                             encrypt:NO
                               block:block];
    [request cache];//获取缓存
}

/**
 ** 健康管理，查询各项指标
 ** userId: 用户ID
 **/
+ (void)queryIndicators:(NSString *)userId comletion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId};
    [AIRequest startWithRequestToURL:nil
                              method:_queryIndicators
                           jsonParam:param
                             encrypt:NO
                               block:block];
}
/**
 ** 健康管理，添加关注各项指标
 ** userId: 用户ID
 ** indicators : 关注的数据的拼接（SG,SZY）
 **/
+ (void)addIndicators:(NSString *)userId indicators:(NSString *)indicators comletion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId,@"followIndicators":indicators};
    [AIRequest startWithRequestToURL:nil
                              method:_addFollowIndicator
                           jsonParam:param
                             encrypt:NO
                               block:block];
}
#pragma mark --- 关爱人模块
/**
 ** 获取关爱人列表
 **/
+ (void)queryUserCareInfos:(NSString *)userId completion:(AICompletionBlock)block {
    NSDictionary *params  = @{@"userId":userId};
    [AIRequest startWithRequestToURL:nil
                              method:_queryUserCareInfos
                           jsonParam:params
                             encrypt:NO
                               block:block];
}

/**
 ** 添加关爱人
 **/
+ (void) addCareUserInfo:(NSString *)userId beCaredPhone:(NSString *)phone beCaredIdCard:(NSString *)idCard beCaredCode:(NSString *)code completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId,@"beCaredPhone":phone,@"validCode":code,@"idCard":idCard};
    [AIRequest startWithRequestToURL:nil
                              method:_addCareUserInfo
                           jsonParam:param
                             encrypt:NO
                               block:block];

}


/**
 ** 删除关爱人
 **/
+ (void) deleteCareUserInfo:(NSString *)userId beCareId:(NSString *)beCareId completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId,@"becareId":beCareId};
    [AIRequest startWithRequestToURL:nil
                              method:_deleteCareUserInfo
                           jsonParam:param
                             encrypt:NO
                               block:block];
}

#pragma mark --- 消息设置
/**
 ** 获取短信设置初始项
 **/
+ (void) queryMessage:(NSString *)userId completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId};
    [AIRequest startWithRequestToURL:nil
                              method:_getMessageState
                           jsonParam:param
                             encrypt:NO
                               block:block];
}


+ (void) setMessageIs:(NSString *)name userId:(NSString *)userId isPush:(NSString *)isPush completion:(AICompletionBlock)block
{
    if ([name isEqualToString:@"sms"]) {
        [self setMessagePush:userId isPush:isPush completion:block];
    }else if ([name isEqualToString:@"push"]){
        [self setMessageSMS:userId isPush:isPush completion:block];
    }
}
/**
 ** 推送Push
 ** isPush （0:否,1是）
 **/
+ (void) setMessagePush:(NSString *)userId isPush:(NSString *)isPush completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId,@"value":isPush};
    [AIRequest startWithRequestToURL:nil
                              method:_isPushMessage
                           jsonParam:param
                             encrypt:NO
                               block:block];
}
/**
 ** 推送短信
 ** isPush （0:否,1是）
 **/
+ (void) setMessageSMS:(NSString *)userId isPush:(NSString *)isPush completion:(AICompletionBlock)block
{
    NSDictionary *param = @{@"userId":userId,@"value":isPush};
    [AIRequest startWithRequestToURL:nil
                              method:_isSMSMessage
                           jsonParam:param
                             encrypt:NO
                               block:block];
}

/**
 * 公益活动
 */
+ (void) gotoActivity:(AICompletionBlock)block{
    [AIRequest startWithRequestToURL:nil
                              method:_gotoActivity
                           jsonParam:nil
                             encrypt:NO
                               block:block];

}
@end
